<?php

namespace api\controller;

use common\controller\VerifyController;
use common\service\ProjectCapacityReportMonthService;
use think\Exception;
use think\Request;
use think\Response;


class ProjectCapacityReportMonthController extends VerifyController
{
    /** @var $reportMonthService */
    protected $reportMonthService;

    public function __construct()
    {
        parent::__construct();
        $this->reportMonthService = ProjectCapacityReportMonthService::getInstance();
    }


    /**
     *  通过年查询
     * @param Request $request
     * @return Response
     */
    public function listByYear(Request $request)
    {
        $param = $request->param()['param'];
        $res = $this->reportMonthService->getMonthReportListByYear($param['project_id'], $param['step_category_id'], $param['report_year']);
        return json(success_response("", $res));
    }


    /**
     * 保存单条上报(月)
     * @param Request $request
     * @return Response
     */
    public function saveReportMonthData(Request $request)
    {
        $param = $request->param()['param'];
        try {
            $res = $this->reportMonthService->saveProjectCapacityReportMonth($param);
        } catch (\Throwable $e) {
            throw_strack_exception($e->getMessage(), $e->getCode());
        }
        return json(success_response("", $res));
    }

}
